package com.eat.netty_server;

import com.eat.netty_server.netty.NettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

 //exclude = {DataSourceAutoConfiguration.class}：springboot启动不加载数据库
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) //让启动类实现CommandLineRunner，重写run方法来实现资源（netty）初始化
public class FishServerApplication implements CommandLineRunner {

    @Autowired
    private NettyServer nettyServer;

    @Value("${netty.port}")
    private Integer nettyPort;

    public static void main(String[] args) {
        SpringApplication.run(FishServerApplication.class, args);
    }

    //通过run方法启动netty，以实现springboot和netty的整合
    @Override
    public void run(String... strings) throws  Exception{
        //InetSocketAddress address = new InetSocketAddress("127.0.0.1",6666);
        System.out.println(nettyPort);
        nettyServer.start(nettyPort);
    }

}
